<?php

namespace App\Models\API;

use Auth;
use Illuminate\Database\Eloquent\Model;

class Friend extends Model
{
	protected $appends = ['count_no_read_message'];

    public function user()
    {
    	return $this->belongsTo('App\Models\API\User');
    }

    public function getCountNoReadMessageAttribute()
    {
    	$chatroom = $this->chatroom;
    	$companionId = $this->companion_id;

    	$count = ChatMessage::where([
    		['chatroom_id', $chatroom],
    		['user_id', $companionId],
    		['status', 0]
    	])->count();

    	return $count;
    }
}
